/*
 * Copyright ©2015-2021 Jaemon. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.gitee.jaemon.spring.adorner.core;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Doc注解信息容器
 *
 * @author Jaemon
 * @since 1.0
 */
public enum DocContainer {
    CONTAINER;

    private Map<String, String> classIns;
    private Map<String, String> methodIns;
    private Map<String, String> fieldIns;

    DocContainer() {
        classIns = new ConcurrentHashMap<>();
        methodIns = new ConcurrentHashMap<>();
        fieldIns = new ConcurrentHashMap<>();
    }

    /**
     * 类名容器设值
     *
     * @param className
     *      类权限名
     * @param value
     *      值
     * @return
     *      val
     */
    String classPut(String className, String value) {
        return classIns.put(className, value);
    }

    /**
     * 类名容器设值-缺省时写入
     *
     * @param className
     *      类权限名
     * @param value
     *      值
     * @return
     *      val
     */
    String classPutIfAbsent(String className, String value) {
        return classIns.putIfAbsent(className, value);
    }

    /**
     * 获取类名对应的值
     *
     * @param className
     *      类权限名
     * @param defaultValue
     *      默认值
     * @return
     *      值
     */
    public String classGet(String className, String defaultValue) {
        return classIns.getOrDefault(className, defaultValue);
    }


    /**
     * 方法名容器设值
     *
     * @param methodName
     *      方法名
     * @param value
     *      值
     * @return
     *      val
     */
    String methodPut(String methodName, String value) {
        return methodIns.put(methodName, value);
    }

    /**
     * 方法名容器设值-缺省时写入
     *
     * @param methodName
     *      方法名
     * @param value
     *      值
     * @return
     *      val
     */
    String methodPutIfAbsent(String methodName, String value) {
        return methodIns.putIfAbsent(methodName, value);
    }

    /**
     * 获取方法对应的值
     *
     * @param methodName
     *      方法名
     * @param defaultValue
     *      默认值
     * @return
     *      值
     */
    public String methodGet(String methodName, String defaultValue) {
        return methodIns.getOrDefault(methodName, defaultValue);
    }

    /**
     * 字段属性名容器设值
     *
     * @param fieldName
     *      字段名
     * @param value
     *      值
     * @return
     *      val
     */
    String fieldPut(String fieldName, String value) {
        return fieldIns.put(fieldName, value);
    }

    /**
     * 字段属性名容器设值-缺省时写入
     *
     * @param fieldName
     *      字段名
     * @param value
     *      值
     * @return
     *      val
     */
    String fieldPutIfAbsent(String fieldName, String value) {
        return fieldIns.putIfAbsent(fieldName, value);
    }

    /**
     * 获取字段对应的值
     *
     * @param fieldName
     *      字段名
     * @param defaultValue
     *      默认值
     * @return
     *      值
     */
    public String fieldGet(String fieldName, String defaultValue) {
        return fieldIns.getOrDefault(fieldName, defaultValue);
    }

    /**
     * 查看容器信息
     *
     * @return
     *      容器信息
     */
    public String message() {
        return String.format(
                "class=%d, method=%d, field=%d",
                CONTAINER.classIns.size(), CONTAINER.methodIns.size(), CONTAINER.fieldIns.size()
        );
    }
}